package zucc.edu.repay.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import Bean.budget;
import Util.BaseException;
import Util.HibernateUtil;

public class BudgetDao {
	public void delBudget(budget budget) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.delete(budget);
		tx.commit();
		
	}
	
	public void addBudget(budget budget) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.save(budget);
		tx.commit();
				
	}
	
	public void updateBudget(budget budget) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.update(budget);
		tx.commit();
		
	}
	
	public budget searchBudget(String budgetid) throws BaseException{
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		String hql = "from budget where budgetid = '" + budgetid + "'";
		Query qry = s.createQuery(hql);
		Object budget = qry.uniqueResult();
		tx.commit();
		return (budget)budget;
	}
	
	public List<budget> serarchAllBudget(){//�������û�
		Session s = HibernateUtil.getSessionFactory().getCurrentSession(); 
		Transaction tx = s.beginTransaction();
        String hql = "from budget";  
        Query query = s.createQuery(hql);  
        List<budget> roles = query.list();  
        tx.commit();
        return roles; 
}
	
	
}
